package com.itheima.mapper;

import com.itheima.entity.Emp;
import com.itheima.entity.EmpExpr;
import com.itheima.entity.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    //基于XML开发动态sql
    List<Emp> list(EmpQueryParam param);


//    @Select("select count(*) from emp")
//    Long count();
//
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id limit #{start},#{pageSize}")
//    List<Emp> page(Integer start, Integer pageSize);

//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id")



    @Options(useGeneratedKeys = true,keyProperty = "id")  //获取主键的值并赋给id属性
    @Insert("insert into emp values (null,#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    //批量删除员工信息
    void deleteBatch(List<Integer> ids);


    //回显员工信息
    Emp getById(Integer id);

    @Select("select * from emp where id=#{id}")
    Emp getById2(Integer id);


    //更新员工--动态sql
    void update(Emp emp);


    /**
     * 统计各职位员工人数
     * @return
     */
    @MapKey("pos")  //可以不加，不影响业务...
    List<Map> countByJob();

    @MapKey("name")
    List<Map> countByGender();

    /**
     * 根据部门id统计员工人数
     * @param deptId
     * @return
     */
    @Select("select count(*) from emp where dept_id = #{deptId}")
    Integer countByDeptId(Integer deptId);

    /**
     * 根据用户名和密码查询员工--登录
     * @param emp
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectUsernameAndPassword(Emp emp);




}
